package org.cmcc.pcap.packet.capture;


import org.cmcc.pcap.packet.tcp.TcpProtocolHandler;
import org.cmcc.pcap.packet.tcp.http.HttpHandler;
import org.cmcc.pcap.packet.tcp.https.HttpsHandler;
import org.cmcc.pcap.packet.tcp.tcp.TcpHandler;
import org.cmcc.pcap.packet.udp.UdpHandler;
import org.cmcc.pcap.packet.udp.UdpProtocolHandler;

/**
 * @Auther: zdw
 * @Date: 2019-10-14 10:46
 * @Description:
 */
public class HandlerManager {
    //传入的handler参数
    public static TcpProtocolHandler tcpHandler;
    public static TcpProtocolHandler httpHandler;
    public static TcpProtocolHandler httpsHandler;
    public static UdpProtocolHandler udpHandler;

    /**
     * 获取handler的方法
     * @param type
     * @return
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    public static synchronized TcpProtocolHandler getHandler(String type) throws IllegalAccessException, InstantiationException {
        if("tcp".equals(type))
        {
        	if(tcpHandler==null)
        		tcpHandler = new TcpHandler();
        	return tcpHandler;
        }
        
        if("http".equals(type))
        {
        	if(httpHandler==null)
        		httpHandler = new HttpHandler();
        	return httpHandler;
        }
        
        if("https".equals(type))
        {
        	if(httpsHandler==null)
        		httpsHandler = new HttpsHandler();
        	return httpsHandler;
        }
        return null;
    }

    public static synchronized UdpProtocolHandler getUdpHandler() throws IllegalAccessException, InstantiationException {
        if (udpHandler == null)
        {
        	udpHandler = new UdpHandler();
        }
        return udpHandler;
    }


}
